package core.command
{
	import core.event.SocketEventID;
	import core.event.UnoEvent;
	import core.event.ViewEventID;

	public class PlayCardCommand extends SuperCommand
	{
		public function PlayCardCommand()
		{
			socketEvent = SocketEventID.PLAY_CARD;
			viewEvent = ViewEventID.PLAY_CARD;
		}
		
		override public function success(e:UnoEvent):void
		{
			//当前玩家的牌有座位信息
			var obj:Object = db.tableList[db.loginUser.table].config[db.userList[e.data.userID].seatID];
			
			var key:String;
			
			if(e.data.type == "normal")
			{
				//出牌
				
				for(key in obj.cards)
				{
					if(obj.cards[key] == e.data.cardID)
					{
						delete obj.cards[key];
						break;
					}
				}
			}
			else if(e.data.type == "turn")
			{
				//抢出牌
				
			}
			else if(e.data.type == "rule")
			{
				var nKey:int = 0;
				for(key in obj.cards)
				{
					nKey = Math.max(nKey, int(key));
				}
				
				for(var i:int = 0; i<e.data.card.length; i++)
				{
					obj[++nKey] = e.data.card[i];
				}
			}
			else
			{
				//罚牌
				
				
				//todo
				//for()
			}
		}
	}
}